package top.zlcode.common.message.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

@Configuration
public class EmailConfig {


    @Value("${zlcode.email.host:}")
    private String host;

    @Value("${zlcode.email.port:}")
    private int port;

    @Value("${zlcode.email.username:}")
    private String username;

    @Value("${zlcode.email.password:}")
    private String password;

    @Value("${zlcode.email.protocol:}")
    private String protocol;

    @Value("${zlcode.email.encoding:}")
    private String encoding;

    @Bean
    public JavaMailSender javaMailSender() {
        JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
        javaMailSender.setHost(host);
        javaMailSender.setPort(port);
        javaMailSender.setUsername(username);
        javaMailSender.setPassword(password);
        javaMailSender.setProtocol(protocol);
        javaMailSender.setDefaultEncoding(encoding);
        return javaMailSender;
    }

}
